package com.jsbs.iam.component.config;

import com.jsbs.iam.component.filter.AuthorityFilter;
import com.jsbs.iam.component.filter.IdentityFilter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;

@Configuration
public class FilterConfig {

    @Resource
    private IdentityFilter identityFilter;

    @Resource
    private AuthorityFilter authorityFilter;

    @Bean
    public FilterRegistrationBean IdentityFilter(){
        FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean();
        filterRegistrationBean.setFilter(identityFilter);
        filterRegistrationBean.addUrlPatterns("/*");
        filterRegistrationBean.setName("IdentityFilter");
        filterRegistrationBean.setOrder(1);
        return filterRegistrationBean;
    }

    @Bean
    public FilterRegistrationBean AuthorityFilter(){
        FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean();
        filterRegistrationBean.setFilter(authorityFilter);
        filterRegistrationBean.addUrlPatterns("/*");
        filterRegistrationBean.setName("AuthorityFilter");
        filterRegistrationBean.setOrder(2);
        return filterRegistrationBean;
    }
}
